﻿#ifndef _FD_PMODELXMLIMPORTOR_H_
#define _FD_PMODELXMLIMPORTOR_H_ 

#include "../dll_cfg.h"
#include "kernel/OgreStringVector.h"
#include "udataset/mdb/ModelDataSource.h"
#include "kernel/file.h"

namespace FD
{
	namespace Kernel
	{
		class Log;
	}
}

namespace FD
{
	namespace Utility
	{
		namespace Dataset
		{
			//导入过程监听
			class FD_XDataset_Export PModelXmlListener
			{
			public:
				virtual ~PModelXmlListener(){}
			public:
				virtual void notifyBeginImportFile(const String& msg, UINT32 currentNo, UINT32 totalNum){}
				virtual void notifyEndImportFile(const String& msg, UINT32 currentNo, UINT32 totalNum, bool suc){}
			};

			class PModelXmlImportInternal;

			//导入工具
			class FD_XDataset_Export PModelXmlImportor 
			{
				friend class PModelXmlImportInternal;
			public:
				PModelXmlImportor();
				virtual ~PModelXmlImportor();

			public:
				bool openSourceDB(FD::Utility::Dataset::ModelDBSourceType type, const String& host
					,UINT32 port, const String& dbName, const String& user, const String& password);

				void closeSourceDB();

				void setImportPModelXmlFile(const String& author, const String& modelName, FD::Kernel::StringVector& treeXmls, FD::Kernel::StringVector& attrXmls){mPModelName = modelName; mTreeXmls = treeXmls; mAttrXmls = attrXmls;mAuthor=author;}

				uint32 existPModel(const String& modelName);

				void removePModel(const String& modelName);

				void addListener(PModelXmlListener* lis);

				void removeListener(PModelXmlListener* lis);

				void setLogFile(const String& log){mLogFile = log;}
				
				String getLogFile(){return mLogFile;}

				//异步导入，通过监听器监听
				void executeImport(bool syn = false);

			protected:
				void log(const String& msg);

			protected:
				typedef std::set<PModelXmlListener*> ImportLis;
				ImportLis mLis;

				String mModelDBName;
				FD::Kernel::StringVector mTreeXmls;
				FD::Kernel::StringVector mAttrXmls;
				String mPModelName;
				String mAuthor;
				String mLogFile;
				FD::Kernel::Log* mpLog;
				PModelXmlImportInternal* mpInternal;
				FD::Utility::Dataset::ModelDataSource* mpSource;
			};
			
		}
	}
}


#endif
